package com.bringway.p2p.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bringway.framework.controller.JsonController;
import com.bringway.framework.util.RequestUtils;
import com.bringway.p2p.service.TgsyService;

/**
 * 
 * @author zhai
 * @version 创建时间：2015年12月16日 上午9:34:42
 * @功能：推广收益界面
 */
@Controller
@RequestMapping("/tgsy")
public class TgsyController extends JsonController{
	
	
	
	@Autowired
	private TgsyService tgsyService;
	
	
	/**
	 * 
	 * @param request 获取数据集
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryTgsyList")
	public ModelAndView queryTgsyList(HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject result = new JSONObject();
		JSONObject params = new JSONObject();
		
		Integer page = RequestUtils.getIntParameter(request, "page");//新版本,传参
		Integer start = RequestUtils.getIntParameter(request, "start");
		Integer limit = RequestUtils.getIntParameter(request, "limit");
		if (null!=page) {//新版本,传参
			start=(page-1)*limit;
		}
		String startDate = RequestUtils.getStringParameter(request, "startDate");
		String endDate = RequestUtils.getStringParameter(request, "endDate");
		
		
		String vipusername = RequestUtils.getStringParameter(request, "vipusername");
		String vipsjhm = RequestUtils.getStringParameter(request, "vipsjhm");
		String syrusername= RequestUtils.getStringParameter(request, "syrusername");
		String syrsjhm = RequestUtils.getStringParameter(request, "syrsjhm");
		String state = RequestUtils.getStringParameter(request, "state");
		
		params.put("start", start);
		params.put("limit", limit);
		params.put("startDate", startDate);
		params.put("endDate", endDate);
		
		params.put("vipusername", vipusername);
		params.put("vipsjhm", vipsjhm);
		params.put("syrusername", syrusername);
		params.put("syrsjhm", syrsjhm);
		params.put("state", state);
		
		List list = tgsyService.queryTgsyList(params);
		int count = tgsyService.getTgsyCount(params);
		result.put("data", list);	
		result.put("total", count);
		if (null!=page) {//新版本,传参
			int totalPage=count%limit==0?count/limit:count/limit+1;
			result.put("totalPage", totalPage);
		}
		serialize(request,response,result);
		return null;
	}
}
